/**
 * @Author：ming
 * @Date：2023/10/29 11:45 PM
 * @Filename：Hot101
 */

/**
 * @author ming
 */
public class Hot101 {
    public boolean isSymmetric(TreeNode root) {
        if(root==null){
            return true;
        }
        if(root.left==null&&root.right==null){
            return true;
        }
        TreeNode p = invertTree(root.left);

        return isSame(p,root.right);
    }
    public static boolean isSame(TreeNode l,TreeNode r){
        if(l==null&&r==null){
            return true;
        }
        if(l!=null&&r!=null){
            return l.val==r.val&&isSame(l.left,r.left)&&isSame(l.right,r.right);
        }

        return false;
    }
    public TreeNode invertTree(TreeNode root) {
        if(root==null){
            return null;
        }

        invertTree(root.left);
        invertTree(root.right);
        TreeNode left = root.left;
        TreeNode right = root.right;
        root.left = right;
        root.right = left;


        return root;
    }
}
